package com.wqz.servlet;

import com.alibaba.fastjson.JSONObject;
import com.wqz.pojo.User;
import com.wqz.service.UserServiceDao;
import com.wqz.service.impl.UserServiceDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/userServlet02")
public class userServlet02 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int id = Integer.parseInt(request.getParameter("id"));
        UserServiceDao userServiceDao = new UserServiceDaoImpl();
        List<User> userList = null;
        try {
            userList = userServiceDao.findUserListById(id);
            System.out.println(userList.size());
            System.out.println(userList);
        } catch (Exception e) {
            e.printStackTrace();
        }

        JSONObject jsonObject = new JSONObject();
        response.setCharacterEncoding("gbk");
        response.getWriter().print(jsonObject.toJSONString(userList));
    }
}
